Skip to content

Feature/db size - #16

Merged
danielbachhuber merged 16 commits into
wp-cli:masterfrom
petenelson:feature/db-size
May 25, 2017
Merged

danielbachhuber merged 16 commits into
wp-cli:masterfrom
petenelson:feature/db-size

Conversation

@petenelson

Copy link
Copy Markdown
Contributor

Adds db size command, raised in #1

@danielbachhuber danielbachhuber left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few comments

Comment thread src/DB_Command.php Outdated
*/
public function size( $args, $assoc_args ) {

WP_CLI::get_runner()-> load_wordpress();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can suppress this with @ for now.

Comment thread src/DB_Command.php Outdated
* ## OPTIONS
*
* [--db-only]
* : Only display the database size without including the tables.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For syntax, what do you think about this?

$ wp db size
# Prints database name and size as ASCII table
$ wp db size --tables
# Prints each table name and size as ASCII table

This would differ a little bit from what you have in that the default would be only the database size, and then you'd use the --tables flag to list all tables.

Comment thread src/DB_Command.php Outdated
* - table
* - csv
* - json
* - bytes, only works when combined with --db-only

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this might work better as a --size_format=<format> argument that accepts one of b, kb, or mb. The default could be kb.

Comment thread composer.json
"db import",
"db tables"
"db tables",
"db size"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good find.

@petenelson

Copy link
Copy Markdown
Contributor Author

Updated with changes (--tables, --size_format)

@danielbachhuber danielbachhuber left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! Some minor comments to address

Comment thread src/DB_Command.php Outdated
*
* $ wp db size
* +-------------------+------+---------+
* | Name | Size | Bytes |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to keep the "Bytes" column if you have the "Size" column?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I can get that removed.

Comment thread src/DB_Command.php Outdated
}

/**
* Display the database name and size as ASCII table.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because you can also display the database name and size in other formats too, does it make sense to explicitly describe this as "ASCII table?

Comment thread src/DB_Command.php Outdated
/**
* Display the database name and size as ASCII table.
*
* Displays the Display the database name and size as ASCII table for `DB_NAME` specified in wp-config.php.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Displays the Display the database name" seems like a typo.

In this extended description, it'd be worthwhile to mention the default size format (which is configurable).

Comment thread src/DB_Command.php Outdated
$format = WP_CLI\Utils\get_flag_value( $assoc_args, 'format' );
$size_format = WP_CLI\Utils\get_flag_value( $assoc_args, 'size_format' );

// For PHP 5.3 compat.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment seems unnecessary, because it's not clear what was added for 5.3 compat (vs. what was removed)

Comment thread src/DB_Command.php
* 6
*/
public function size( $args, $assoc_args ) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I provide --scope=<scope>, --network, --all-tables-with-prefix or --all-tables without the --tables flag, what should happen?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Went with the same flags and docblock as the tables command, but I can add sample output if you'd like.

@danielbachhuber

Copy link
Copy Markdown
Member

@petenelson Happy with this? Ready to merge it?

@danielbachhuber

Copy link
Copy Markdown
Member

It looks like tests still fail intermittently because the database size changes between command executions :(

I'd suggest we can drop the explicit size assertions. I can't think of a good workaround at this point, and it's not worth blocking the pull request.

@petenelson

Copy link
Copy Markdown
Contributor Author

That was one of the things I was worried would happen with MySQL doing things in the background. I'll get the tests updated shortly.

@danielbachhuber danielbachhuber added this to the 1.0.2 milestone May 25, 2017
@danielbachhuber danielbachhuber added command:db Related to 'db' command command:db-size Related to 'db size' command labels May 25, 2017
@danielbachhuber

Copy link
Copy Markdown
Member

👌 Thanks for your work on this, @petenelson

@danielbachhuber
danielbachhuber merged commit c1f1791 into wp-cli:master May 25, 2017
@petenelson

Copy link
Copy Markdown
Contributor Author

You're welcome, thanks for entrusting me with is change!

danielbachhuber added a commit that referenced this pull request Nov 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

command:db Related to 'db' command command:db-size Related to 'db size' command

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants